home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
ACORNUSERS
/
EMULATOR
/
EMUL6502
/
Sources
/
StringCmp
< prev
next >
Wrap
Text File
|
1998-08-27
|
2KB
|
60 lines
;Alain BROBECKER (aka baah/Arm's Tech), 06jun1998.
;
;This program counts the number of identical chars in two strings, until one
;string contains the LF char. Also uses stack to save X counter. The result is
;then compared to the ones computed by hand, and if it is different it jumps
;at adress 0 (should contain &00='brk'), else it ends with the 'brk' inside
;the code (and so the 6502 emulation went ok).
#name StringCmpX
#list
#base &100-4 ;Start assembly here
#rw &100 ;Load adress
#rw &100 ;Exec adress
ldx #&ff ;Position in string
ldy #0 ;Nb of identical chars
.compare_one
inx ;Pos+=1
lda string1,x ;A=char1
cmp string2,x ;Flags=char1-char2
bne not_the_same
iny ;One more identical char
cmp #&a ;Flags=char1-&a=char2-&a
beq lf_found ;End if LF
bne compare_one
.not_the_same
cmp #&a ;Flags=char1-&a
beq lf_found ;End if LF
lda string2,x ;A=char2
cmp #&a ;Flags=char1-&a
bne compare_one ;Next char
.lf_found
;Here Y contains nb of identical chars, and X contains nb of chars-1,
;so X+1-Y shall contain nb of different chars. Compare all this with
;results computed by end.
inx
cpx #string2-string1
beq nb_chars_ok
.error
jmp 0
.nb_chars_ok
cpy #10 ;Nb of identical chars ok?
bne error
txa
sty for_sbc+1
sec
.for_sbc
sbc #0 ;A=X+1-Y (-1+C=0)
cmp #string2-string1-10 ;Nb of different chars ok?
bne error
brk
.string1
#b &65,&6D,&75,&6C,&36,&35,&30,&32,&20,&62,&79,&20,&62,&61,&61,&68
#b &2F,&41,&72,&6D,&27,&73,&20,&54,&65,&63,&68,&0A
.string2
#b &45,&6D,&75,&36,&35,&63,&30,&32,&20,&66,&72,&6F,&6D,&20,&74,&68
#b &65,&20,&72,&75,&6D,&73,&54,&65,&61,&63,&6B,&0A